import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: () => import("../views/home/HomeView.vue"),
    },
    {
      path: "/login",
      name: "login",
      component: () => import("../views/login/LoginView.vue"),
    },
    {
      path: "/extension",
      name: "extension",
      meta: { isAuth: true },
      component: () => import("../views/extension/ExtensionView.vue"),
      redirect: "/",
      children: [
        // {
        //   path: "file-camouflage-picture",
        //   meta: { title: "文件伪装图片" },
        //   component: () =>
        //     import("../views/extension/pages/FileCamouflagePicture.vue"),
        // },
        {
          path: "video",
          name: "video",
          meta: { title: "录屏" },
          component: () => import("../views/app/Video.vue"),
        },
        {
          path: "commemorate",
          name: "commemorate",
          meta: { title: "行程卡纪念版" },
          component: () => import("../views/app/CommemorateCard.vue"),
        },
        {
          path: "jsonswitch",
          name: "jsonswitch",
          meta: { title: "json转化" },
          component: () => import("@/views/app/JsonSwitch.vue"),
        },
        {
          path: "ipswitch",
          name: "ipswitch",
          meta: { title: "ip地址转化" },
          component: () => import("@/views/app/IpSwitch.vue"),
        },
        {
          path: "nodup",
          name: "nodup",
          meta: { title: "文本去重" },
          component: () => import("@/views/app/nodup.vue"),
        },
        {
          path: "ipcount",
          name: "ipcount",
          meta: { title: "ip计算" },
          component: () => import("@/views/app/IpCount.vue"),
        },
        {
          path: "qrcode",
          name: "qrcode",
          meta: { title: "二维码生成" },
          component: () => import("@/views/app/QRcode.vue"),
        },
        {
          path: "idcard",
          name: "idcard",
          meta: { title: "身份证号解析" },
          component: () => import("@/views/app/IdCard.vue"),
        },
        {
          path: "sayswitch",
          name: "sayswitch",
          meta: { title: "文本转语音" },
          component: () => import("@/views/app/SaySwitch.vue"),
        },
        {
          path: "ImageOrc",
          name: "ImageOrc",
          meta: { title: "图片提取文字" },
          component: () => import("@/views/app/ImageOrc.vue"),
        },
      ],
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.meta.isAuth) {
    if (localStorage.token) {
      next();
    } else {
      ElMessage({
        showClose: true,
        message: "你还没登录",
        type: "warning",
      });
      next("/login");
    }
  } else {
    next();
  }
});
export default router;
